/**
 * @(#)ApkConfigController.java 2016年12月1日
 * Copyright(C) 2016 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.jsbd.boss.annotation.SystemControllerLog;
import org.jsbd.boss.common.ResponseUtils;
import org.jsbd.boss.domian.SimulatorApkDownloadConfig;
import org.jsbd.boss.domian.SimulatorUVConfig;
import org.jsbd.boss.service.ISimulatorUVService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
 * 母包apk配置
 * @author <a href="mailto:zhangbinghua@zhexinit.com" >zbh</a>
 * @version 1.0.0
 */
@Controller
@RequestMapping("/simulatoruv")
public class SimulatorUVConfigController {
	public static final Logger LOGGER = LoggerFactory.getLogger(SimulatorUVConfigController.class);

	@Resource
	private ISimulatorUVService simulatorUVService;

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list() {
		return "/simulatoruv/configList";
	}

	@RequestMapping(value = "addConfig", method = RequestMethod.GET)
	public String add() {
		return "/simulatoruv/add";
	}


	@RequestMapping(value = "effect")
	@SystemControllerLog(description = "生效")
	public void effect(String id, HttpServletResponse response) {
		try {
			simulatorUVService.effectSimulatorUVConfig(id);
			ResponseUtils.responseSuccess(response);
		} catch (Exception e) {
			LOGGER.error("生效apk出错", e);
			ResponseUtils.responseFailure(response);
		}
	}

	@RequestMapping(value = "abandon")
	@SystemControllerLog(description = "作废")
	public void abandon(String id, HttpServletResponse response) {
		try {
			simulatorUVService.abondeSimulatorUVConfig(id);
			ResponseUtils.responseSuccess(response);
		} catch (Exception e) {
			LOGGER.error("废弃apk出错", e);
			ResponseUtils.responseFailure(response);
		}
	}

	@RequestMapping(value = "saveConfig", method = RequestMethod.POST)
	@SystemControllerLog(description = "新增配置")
	public void saveConfig(SimulatorUVConfig config, HttpServletResponse response) {
		try {
			simulatorUVService.saveSimulatorUVConfig(config);
			ResponseUtils.responseSuccess(response);
		}
		catch (Exception e) {
			LOGGER.error("保存出错", e);
			ResponseUtils.responseInfoExists(response);
		}
	}
	
	@RequestMapping(value = "updateConfig", method = RequestMethod.POST)
	@SystemControllerLog(description = "新增配置")
	public void updateConfig(SimulatorUVConfig config, HttpServletResponse response) {
		try {
			simulatorUVService.updateSimulatorUVConfig(config);
			ResponseUtils.responseSuccess(response);
		}
		catch (Exception e) {
			LOGGER.error("保存出错", e);
			ResponseUtils.responseInfoExists(response);
		}
	}

	@RequestMapping(value = "configList", params = "json")
	@ResponseBody
	public Map<String, Object> configPageList(SimulatorUVConfig config) {
		return  simulatorUVService.getApkConfigByPage(config);
	}

}
